package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Poetry;
import com.woniuxy.mapper.PoetryMapper;
import com.woniuxy.service.PoetryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PoetryServiceImpl implements PoetryService {

    private PoetryMapper poetryMapper;

    @Autowired
    public void setPoetryMapper(PoetryMapper poetryMapper) {
        this.poetryMapper = poetryMapper;
    }

    @Override
    public PageInfo<Poetry> findOnePage(int currentPage, Poetry poetry) {
        if(currentPage == 0) return null;
        PageHelper.startPage(currentPage,2);
        List<Poetry> list = poetryMapper.findCondition(poetry);
        PageInfo<Poetry> info = null;
        if(list != null){
            info = new PageInfo<>(list);
        }
        return info;
    }

    @Override
    public boolean deleteByIds(Integer[] ids) {
        int row = poetryMapper.deletByIds(ids);
        return row>0;
    }

    @Override
    public boolean updata(Poetry poetry) {
        int row = poetryMapper.updata(poetry);
        return row>0;
    }

    @Override
    public boolean add(Poetry poetry) {
        int row = poetryMapper.add(poetry);
        return row>0;
    }
}
